import 'package:flutter/material.dart';
import 'package:flutter_base/common/dialog.dart';
import 'package:flutter_base/common/routeUtil.dart';
import 'package:flutter_base/net/api.dart';
import 'package:flutter_base/pages/demo/chartPage.dart';
import 'package:flutter_base/pages/demo/dialogPage.dart';
import 'package:flutter_base/pages/demo/loadImagePage.dart';
import 'package:flutter_base/pages/demo/secondPage.dart';
import 'package:flutter_base/widgets/base/basePage.dart';
import 'package:flutter_base/widgets/commonWidgets.dart';

/// Create： Zhang 3/18/21 10:42 AM
/// 描述：首页

class HomePage extends BasePage {
  HomePage() : super(title: "首页", isFirstPage: true);

  @override
  PageState createState() => Content();
}

class Content extends PageState {
  //定义页面数据
  var _getData = "网络请求";

  @override
  Widget? content(BuildContext context) {
    //可滚动部件
    return SingleChildScrollView(
      child: Column(
        children: [
          commonItem(
            "页面跳转",
            onClick: () {
              goTo(context, SecondPage());
            },
          ),
          commonItem(
            _getData,
            onClick: () {
              setState(() {
                _getData = "请求中...";
              });
              login(
                "zhang410726",
                "123456",
                (res) {
                  toastSuc(msg: "请求成功");
                  setState(() {
                    //使用获取的结果更新状态
                    _getData = "用户名:" + res.data!.nickname!;
                  });
                },
              );
            },
          ),
          commonItem(
            "提示框",
            onClick: () {
              goTo(context, DialogPage());
            },
          ),
          commonItem(
            "加载本地图标",
            onClick: () {
              goTo(context, LoadImagePage());
            },
          ),
          commonItem(
            "图表FL Chart",
            onClick: () {
              goTo(context, ChartPage());
            },
          ),
        ],
      ),
    );
  }
}
